const { ccclass, property } = cc._decorator;

import n from "./frameworkManager"
import l from "./NodePool"
import s from "./EngineUtil"
import c from "./MathUtil"
import u from "./MatchGameConfig"
import p, { ObstacleAllType, SpecifyColor } from "./ObstacleConfig"
import d from "./MatchGameAudioMgr"
import h from "./MatchGameDataMgr"
import f from "./MatchGameUtilsDataMgr"
import g from "./DrillFill"
import y from "./MatchAniCtrl"
import MatchGameConfig from "./MatchGameConfig";
import MathUtils from "./MathUtil";

@ccclass
class ObstacleAniCtrl {

    public obstacleEffectPrefab = null;
    public grassEffectSpData = null;
    public grassLandEffectSpData = null;
    public colorBoxEffectSpData = null;
    public eggEffectSpData = null;
    public colorBottleEffectSpData = null;
    public vaseEffectSpData = null;
    public honeyEffectSpData = null;
    public icicleDestoryEffectSpData = null;
    public iceEffectSpData = null;
    public curtainDestoryEffectSpData = null;
    public curtainStarEffectSpData = null;
    public oysterEffectSpData = null;
    public flowerpotEffectSpData = null;
    public stoneEffectSpData = null;
    public safeBoxSpData = null;
    public pigEffectSpData = null;
    public cupboardDestoryEffectSpData = null;
    public BirdNestEffectSpData = null;
    public RockEffectSpData = null;
    public cupboardDoorEffectSpData = null;
    public plateDestoryEffectSpData = null;
    public cupboardDestorySpData = null;
    public magicHatEffectSpData = null;
    public mailEffectSpData = null;
    public coinEffectSpData = null;
    public bottleOneBoomEffectSpData = null;
    public bottleOneEffectSpData = null;
    public mailFlySpData = null;
    public birdFlyEffectSpData = null;
    public matchFlySpData = null;
    public birdFlySpData = null;
    public goldCoinFlySpData = null;
    public targetEffectParent = null;
    public candleDestoryEffectSpData = null;
    public cupDestoryEffectSpData = null;
    public cupHolderDestoryEffectSpData = null;
    public drillEffectSApData = null;
    public effectParent = null;
    public isReady = false;
    constructor() {
        this.obstacleEffectPrefab = null;
        this.grassEffectSpData = null;
        this.grassLandEffectSpData = null;
        this.colorBoxEffectSpData = null;
        this.eggEffectSpData = null;
        this.colorBottleEffectSpData = null;
        this.vaseEffectSpData = null;
        this.honeyEffectSpData = null;
        this.icicleDestoryEffectSpData = null;
        this.iceEffectSpData = null;
        this.curtainDestoryEffectSpData = null;
        this.curtainStarEffectSpData = null;
        this.oysterEffectSpData = null;
        this.flowerpotEffectSpData = null;
        this.stoneEffectSpData = null;
        this.safeBoxSpData = null;
        this.pigEffectSpData = null;
        this.cupboardDestoryEffectSpData = null;
        this.BirdNestEffectSpData = null;
        this.RockEffectSpData = null;
        this.cupboardDoorEffectSpData = null;
        this.plateDestoryEffectSpData = null;
        this.cupboardDestorySpData = null;
        this.magicHatEffectSpData = null;
        this.mailEffectSpData = null;
        this.coinEffectSpData = null;
        this.bottleOneBoomEffectSpData = null;
        this.bottleOneEffectSpData = null;
        this.mailFlySpData = null;
        this.birdFlyEffectSpData = null;
        this.matchFlySpData = null;
        this.birdFlySpData = null;
        this.goldCoinFlySpData = null;
        this.targetEffectParent = null;
        this.candleDestoryEffectSpData = null;
        this.cupDestoryEffectSpData = null;
        this.cupHolderDestoryEffectSpData = null;
        this.drillEffectSApData = null;
        this.effectParent = null;
        this.isReady = false;
    }
    static _instance;
    static getInstance(): ObstacleAniCtrl {
        this._instance || (this._instance = new ObstacleAniCtrl());
        return this._instance;
    };
    public ready(e, t) {
        this.isReady = true;
        this.effectParent = e;
        this.targetEffectParent = t;
    };
    public async init() {
        return new Promise<void>(async (resolve, reject) => {
            await this.loadObstaclePrefab();
            await this.loadObstacleSpData();
            await this.loadMatchFlySpData();
            await this.loadBirdFlySpData();
            resolve();
        });
        
    };
    public loadMatchFlySpData() {
        var e = this;
        return new Promise(function (t, a) {
            cc.resources.load("spine/all/QiZi", sp.SkeletonData, function (o, i) {
                if (o) {
                    n.error("未找到障碍物特效动画预制体", o);
                    a();
                }
                e.matchFlySpData = i;
                t(i);
            });
        });
    };
    public loadBirdFlySpData() {
        var e = this;
        return new Promise(function (t, a) {
            cc.resources.load("spine/obstacleEffect/XiaoNiao", sp.SkeletonData, function (o, i) {
                if (o) {
                    n.error("未找到障碍物特效动画预制体", o);
                    a();
                }
                e.birdFlySpData = i;
                t(i);
            });
        });
    };
    public loadObstaclePrefab() {
        var e = this;
        return new Promise(function (t, a) {
            cc.resources.load("prefabs/obstacleAniPrefab", cc.Prefab, function (o, i) {
                if (o) {
                    n.error("未找到障碍物特效动画预制体", o);
                    a();
                }
                e.obstacleEffectPrefab = i;
                l.initPool(e.obstacleEffectPrefab, 0, u.MatchAniPool.obstacleAniPrefab);
                t(i);
            });
        });
    };
    public loadObstacleSpData(cb?) {
        var e = this;
        return new Promise(function (t, a) {
            cb && cb();
            if(e.grassEffectSpData){
                t(null);
                return;
            }
            cc.resources.loadDir("spine/obstacleEffect", sp.SkeletonData, function (o, i) {
                if (o) {
                    n.error("加载单个道具使用动画数据报错", o);
                    a();
                }
                i.forEach(function (t) {
                    switch (t.name) {
                        case "CaoPing":
                            e.grassEffectSpData = t;
                            break;

                        case "Em_MuLi":
                            e.oysterEffectSpData = t;
                            break;

                        case "FengMi":
                            e.honeyEffectSpData = t;
                            break;

                        case "HuaPen":
                            e.flowerpotEffectSpData = t;
                            break;

                        case "HuaPing":
                            e.vaseEffectSpData = t;
                            break;

                        case "JiDan":
                            e.eggEffectSpData = t;
                            break;

                        case "JinBi_1":
                            e.coinEffectSpData = t;
                            break;

                        case "MoFaMao":
                            e.magicHatEffectSpData = t;
                            break;

                        case "MuHe":
                            e.colorBoxEffectSpData = t;
                            break;

                        case "ShiXiang":
                            e.stoneEffectSpData = t;
                            break;

                        case "Em_SuiBingQi":
                            e.icicleDestoryEffectSpData = t;
                            break;

                        case "XiaoZhu":
                            e.pigEffectSpData = t;
                            break;

                        case "YaoPing":
                            e.bottleOneBoomEffectSpData = t;
                            break;

                        case "YaoPingKuang":
                            e.colorBottleEffectSpData = t;
                            break;

                        case "ChuGui_Gui_em":
                            e.cupboardDestoryEffectSpData = t;
                            break;

                        case "ChuGui_Men":
                            e.cupboardDoorEffectSpData = t;
                            break;

                        case "ChuGui_Gui_em":
                            e.cupboardDestorySpData = t;
                            break;

                        case "ChuGui_PanZi_em":
                            e.plateDestoryEffectSpData = t;
                            break;

                        case "GuanMuCong":
                            e.grassLandEffectSpData = t;
                            break;

                        case "BingKuai":
                            e.iceEffectSpData = t;
                            break;

                        case "ChuangLian":
                            e.curtainDestoryEffectSpData = t;
                            break;

                        case "C_XingXing":
                            e.curtainStarEffectSpData = t;
                            break;

                        case "XinFeng":
                            e.mailFlySpData = t;
                            break;

                        case "XiaoNiao":
                            e.birdFlyEffectSpData = t;
                            break;

                        case "BaoXianXiang":
                            e.safeBoxSpData = t;
                            break;

                        case "QZ_HongBao":
                            e.goldCoinFlySpData = t;
                            break;

                        case "N_E_NiaoChao":
                            e.BirdNestEffectSpData = t;
                            break;

                        case "Z_E_ZhaYaoHe_he":
                            e.candleDestoryEffectSpData = t;
                            break;

                        case "Y_E_YanShi_BaoShi":
                            e.RockEffectSpData = t;
                            break;

                        case "B_BeiJia":
                            e.cupHolderDestoryEffectSpData = t;
                            break;

                        case "B_E_BeiZi":
                            e.cupDestoryEffectSpData = t;
                            break;

                        case "Z_A_ZuanTou":
                            e.drillEffectSApData = t;
                    }
                });
                t(null);
            });
        });
    };
    public createObstacleEffectItem(e, t, a?) {
        var o = l.getNode(u.MatchAniPool.obstacleAniPrefab);
        o.parent = this.effectParent;
        o.setPosition(this.getV3Pos(e.row, e.col));
        var i = o.getComponent(sp.Skeleton);
        o.angle = 0;
        i.skeletonData = t;
        i.premultipliedAlpha = false;
        i.clearTracks();
        i.setCompleteListener(function () {
            i.setCompleteListener(null);
            i.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, o);
            a && a();
        });
        return i;
    };
    public playObstacleEffectAni(e, t, a?) {
        d.playObstacleEffectAUdio(t);
        var o, i = null, r = null, n = 0, l = 0;
        switch (t.ObstacleAllType) {
            case ObstacleAllType.WoodenBox:
                o = this.colorBoxEffectSpData;
                i = 0 == t.Hp ? "explode_4" : 1 == t.Hp ? "explode_3" : 2 == t.Hp ? "explode_2" : "explode_1";
                switch (t.SpecifyColor) {
                    case SpecifyColor.any:
                        r = "YiBan";
                        break;

                    case SpecifyColor.blueShield:
                        r = "Lan";
                        break;

                    case SpecifyColor.yellowCrown:
                        r = "Huang";
                        break;

                    case SpecifyColor.purpleGem:
                        r = "Zi";
                        break;

                    case SpecifyColor.greenLeaf:
                        r = "Lv";
                        break;

                    case SpecifyColor.redBook:
                        r = "Hong";
                }
                break;

            case ObstacleAllType.ColorBox:
                o = this.colorBoxEffectSpData;
                i = 0 == t.Hp ? "explode_4" : 1 == t.Hp ? "explode_3" : 2 == t.Hp ? "explode_2" : "explode_1";
                switch (t.SpecifyColor) {
                    case SpecifyColor.any:
                        r = "YiBan";
                        break;

                    case SpecifyColor.blueShield:
                        r = "Lan";
                        break;

                    case SpecifyColor.yellowCrown:
                        r = "Huang";
                        break;

                    case SpecifyColor.purpleGem:
                        r = "Zi";
                        break;

                    case SpecifyColor.redBook:
                        r = "Hong";
                        break;

                    case SpecifyColor.greenLeaf:
                        r = "Huang";
                }
                break;

            case ObstacleAllType.Grass:
                o = this.grassEffectSpData;
                r = 1 == t.Hp ? "ShenLv" : "QianLv";
                i = "explode";
                break;

            case ObstacleAllType.PurpleFlower:
                o = this.grassEffectSpData;
                r = 1 == t.Hp ? "ShenZi" : "QianZi";
                i = "explode";
                break;

            case ObstacleAllType.GrassLand:
                o = this.grassLandEffectSpData;
                0 == t.Hp ? i = "explode_4" : 1 == t.Hp ? i = "explode_3" : 2 == t.Hp ? i = "explode_3" : 3 == t.Hp ? i = "explode_2" : 4 == t.Hp && (i = "explode_1");
                n = MatchGameConfig.ITEM_WIDTH / 2;
                l = -u.ITEM_HEIGHT / 2;
                break;

            case ObstacleAllType.Egg:
                o = this.eggEffectSpData;
                i = "explode";
                break;

            case ObstacleAllType.ColorBottle:
                break;

            case ObstacleAllType.Vase:
                o = this.vaseEffectSpData;
                i = t.Hp <= 1 ? "explode_1" : "explode_2";
                break;

            case ObstacleAllType.Honey:
                o = this.honeyEffectSpData;
                i = "explode";
                break;

            case ObstacleAllType.Icicle:
            case ObstacleAllType.curtain:
                break;

            case ObstacleAllType.Oyster:
                o = this.oysterEffectSpData;
                i = "explode";
                break;

            case ObstacleAllType.Flowerpot:
                o = this.flowerpotEffectSpData;
                i = t.Hp >= 1 ? "explode_1" : "explode_2";
                break;

            case ObstacleAllType.Stone:
                o = this.stoneEffectSpData;
                i = "explode";
                break;

            case ObstacleAllType.SafeBox:
                o = null;
                break;

            case ObstacleAllType.cupboard:
                break;

            case ObstacleAllType.MagicHat:
            case ObstacleAllType.MailBox:
            case ObstacleAllType.Bird:
                o = null;
                break;

            case ObstacleAllType.GoldCoin:
                o = this.coinEffectSpData;
                i = "break1";
                break;

            case ObstacleAllType.PorcelainPig:
                o = this.pigEffectSpData;
                i = "explode_1";
                break;

            case ObstacleAllType.BirdNest:
                o = this.BirdNestEffectSpData;
                i = "explode_3";
                break;

            case ObstacleAllType.Candlebox:
                break;

            case ObstacleAllType.Rock:
                o = this.RockEffectSpData;
                i = t.Hp <= 1 ? "explode_1" : "explode_2";
        }
        if (i) {
            var s = this.createObstacleEffectItem(e, o, a);
            r && s.setSkin(r);
            s.node.x += n;
            s.node.y += l;
            s.setAnimation(0, i, false);
        } else a && a();
    };
    public playPlateDestoryAni(e, t, a) {
        var o = this.createObstacleEffectItem(e, this.plateDestoryEffectSpData, a);
        o.node.x = e.row * MatchGameConfig.ITEM_WIDTH + t.x;
        o.node.y = -e.col * MatchGameConfig.ITEM_HEIGHT + t.y + 20;
        o.setAnimation(0, "explode", false);
    };
    public playCurboardAni(e, t?, a?) {
        var o, i;
        o = t.Hp <= 0 ? this.cupboardDestoryEffectSpData : this.cupboardDoorEffectSpData;
        i = t.Hp <= 0 ? "explode" : "explode_1";
        var r = this.createObstacleEffectItem(e, o, a);
        r.node.x = e.row * MatchGameConfig.ITEM_WIDTH + 75;
        r.node.y = -e.col * MatchGameConfig.ITEM_HEIGHT - 71;
        r.setAnimation(0, i, false);
    };
    public playIcicleDestoryAni(e, t, a) {
        this.createObstacleEffectItem(e, this.icicleDestoryEffectSpData, a).setAnimation(0, "explode", false);
    };
    public playShortPillarAni(e, t?) {
        this.createObstacleEffectItem(e, this.iceEffectSpData, t).setAnimation(0, "explode", false);
    };
    public playCurtainFlyAni(e, t, a, o) {
        var i = this.createObstacleEffectItem(e, this.matchFlySpData);
        i.setCompleteListener(function () { });
        i.setAnimation(0, "idle_1", false);
        i.setSkin(y.setMatchAniSkin(a));
        var r = cc.v2(i.node.x - t.x > 0 ? t.x + 50 : t.x - 50, t.y - 300);
        cc.tween(i.node).bezierTo(.6, cc.v2(i.node.position), r, cc.v2(t)).call(function () {
            i.setCompleteListener(null);
            i.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, i.node);
            o && o();
        }).start();
    };
    public playCurtainDestoryAni(e, t, a) {
        for (var o = this, i = 0; i < t.w; i++) this.createObstacleEffectItem({
            row: e.row + i,
            col: e.col
        }, this.curtainDestoryEffectSpData).setAnimation(0, "explode_" + s.getRandomNum(1, 3), false);
        h.setGlobalScheduler(function () {
            a && a();
            o.playCurtainStarAni(e, t);
        }, 1);
    };
    public playCurtainStarAni(e, t) {
        for (var a = 0; a < t.w; a++) for (var o = 0; o < t.h; o++) this.createObstacleEffectItem({
            row: e.row + a,
            col: e.col + o
        }, this.curtainStarEffectSpData).setAnimation(0, "Remove_" + s.getRandomNum(1, 3), false);
    };
    public playCreateGemAni(e, t, a) {
        var o = this.createObstacleEffectItem(e, this.matchFlySpData), i = this.getV3Pos(t.row, t.col);
        o.setCompleteListener(function () { });
        o.setAnimation(0, "idle_1", false);
        o.setSkin(y.setMatchAniSkin(u.MatchItemType.purpleGem));
        var r = cc.v2(o.node.x - i.x > 0 ? o.node.position.x + 50 : o.node.position.x - 50, o.node.position.y + 300);
        cc.tween(o.node).delay(.06).bezierTo(.6, cc.v2(o.node.position), r, cc.v2(i)).call(function () {
            o.setCompleteListener(null);
            o.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, o.node);
            a && a();
        }).start();
        return {
            time: .6,
            spine: o
        };
    };
    public playCreateBirdAni(e, t, a, o) {
        var i = this.createObstacleEffectItem(e, this.birdFlySpData);
        i.node.active = true;
        var r = this.getV3Pos(t.row, t.col);
        i.setCompleteListener(function () { });
        i.setAnimation(0, "idle_5", false);
        var n = f.getPos(e.row, e.col);
        n.x = n.x + MatchGameConfig.ITEM_WIDTH;
        n.y = n.y - MatchGameConfig.ITEM_HEIGHT;
        if (0 == a) {
            n.x = n.x - 26;
            n.y = n.y + 12;
        } else if (1 == a) i.node.zIndex = 1; else if (2 == a) {
            n.x = n.x + 26;
            n.y = n.y + 12;
        }
        i.node.setPosition(cc.v3(n.x, n.y, 0));
        var c = cc.v2(0, 0), p = s.getRandomNum(0, 360), h = s.getRandomNum(10, 180), g = s.getPosByRot(h, p), y = g.x, m = g.y, _ = s.getRandomNum(3, 6) / 60;
        if (0 == a) {
            y = -y;
            c = cc.v2(-y - 50, i.node.position.y + 300);
        } else if (1 == a) {
            y = 0;
            c = cc.v2(0, i.node.position.y + 300);
        } else 2 == a && (c = cc.v2(y + 50, i.node.position.y + 300));
        cc.tween(i.node).delay(_).call(function () {
            d.playBirdFly();
        }).bezierTo(1.2, cc.v2(y, m), c, cc.v2(r)).call(function () {
            i.setCompleteListener(null);
            i.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, i.node);
            o && o();
        }).start();
        return {
            time: 1.2 + _,
            spine: i
        };
    };
    public playBottleDestoryAni(e, t?) {
        this.createObstacleEffectItem(e, this.colorBottleEffectSpData, t).setAnimation(0, "explode", false);
    };
    public playSafeBoxEffectAni(e, t, a) {
        var o = this.createObstacleEffectItem(e, this.safeBoxSpData, a), i = t.Hp;
        o.node.x = (e._row) * MatchGameConfig.ITEM_WIDTH;
        o.node.y = (-e.col) * MatchGameConfig.ITEM_HEIGHT;
        o.setAnimation(0, "explode_" + (5 - i), false);
    };
    public playCandleDestoryEffectAni(e, t, a) {
        var o = this.createObstacleEffectItem(e, this.candleDestoryEffectSpData, a);
        o.node.x = (e.row + 1) * MatchGameConfig.ITEM_WIDTH;
        o.node.y = (-e.col - 1) * MatchGameConfig.ITEM_HEIGHT;
        o.setAnimation(0, "Blast", false);
    };
    public playOneBottleDestoryAni(e, t, a, o) {
        var i = this.createObstacleEffectItem(e, this.bottleOneBoomEffectSpData, o);
        i.node.x = e.row * MatchGameConfig.ITEM_WIDTH + t.x;
        i.node.y = -e.col * MatchGameConfig.ITEM_HEIGHT + t.y;
        i.setAnimation(0, "explode", false);
        var r = "";
        switch (a) {
            case u.MatchItemType.blueShield:
                r = "YaoPing_Lan";
                break;

            case u.MatchItemType.greenLeaf:
                r = "YaoPing_Lv";
                break;

            case u.MatchItemType.purpleGem:
                r = "YaoPing_Zi";
                break;

            case u.MatchItemType.redBook:
                r = "YaoPing_Hong";
                break;

            case u.MatchItemType.yellowCrown:
                r = "YaoPing_Huang";
        }
        i.setSkin(r);
    };
    public playCupDestoryEffectAni(e, t, a) {
        console.error("playCupDestoryEffectAni", e);
        this.createObstacleEffectItem(e, this.cupDestoryEffectSpData, a).setAnimation(0, "explode", false);
    };
    public playCupHolderDestoryEffectAni(e, t, a) {
        this.createObstacleEffectItem(e, this.cupHolderDestoryEffectSpData, a).setAnimation(0, "explode_1", false);
    };
    public playMailMoveAni(e, t, a) {
        debugger
        var o = this.createObstacleEffectItem(e, this.mailFlySpData);
        o.setAnimation(0, "explode_1", false);
        var i = MathUtils.getDistance(o.node.position, t) / 1e3;
        o.setCompleteListener(function () {
            cc.tween(o.node).to(i, {
                position: t
            }, {
                easing: "backOut"
            }).delay(.6).call(function () {
                o.setCompleteListener(null);
                o.skeletonData = null;
                l.putNode(u.MatchAniPool.obstacleAniPrefab, o.node);
                a && a();
            }).start();
        });
    };
    public playGoldCoinMoveToRedPackAni(e, t, a) {
        var o = l.getNode(u.MatchAniPool.obstacleAniPrefab);
        o.parent = this.effectParent;
        o.setPosition(e);
        var i = o.getComponent(sp.Skeleton);
        o.angle = 0;
        i.skeletonData = this.goldCoinFlySpData;
        i.premultipliedAlpha = false;
        o.scale = .1;
        i.clearTracks();
        i.setAnimation(0, "idle_2", false);
        var r = MathUtils.getDistance(i.node.position, t) / 600;
        cc.tween(i.node).to(.3, {
            scale: 1
        }, {
            easing: "backOut"
        }).delay(.2).to(r, {
            position: t
        }, {
            easing: "backOut"
        }).delay(.6).call(function () {
            i.setCompleteListener(null);
            i.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, i.node);
            a && a();
        }).start();
    };
    public playMatchFlyAni(e, t, a, o) {
        var i = this.createObstacleEffectItem(e, this.matchFlySpData);
        i.setCompleteListener(null);
        i.setAnimation(0, "idle_1", false);
        i.setSkin(y.setMatchAniSkin(a));
        var r = MathUtils.getDistance(i.node.position, t) / 1e3;
        cc.tween(i.node).to(r, {
            position: t
        }, {
            easing: "backOut"
        }).delay(.6).call(function () {
            i.setCompleteListener(null);
            i.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, i.node);
            o && o();
        }).start();
    };
    public playMailCloseAni() { };
    public playObstacleAni(e, t) {
        if(!t){
            return;
        }
        var a = "", o = e.Hp, i = "", r = null, l = e.ObstacleAllType;
        if (Number(l) == ObstacleAllType.WoodenBox) {
            a = "M_A_MuHe";
            i = "idle_" + o;
            switch (e.SpecifyColor) {
                case SpecifyColor.any:
                    r = "YiBan";
                    break;

                case SpecifyColor.blueShield:
                    r = "Lan";
                    break;

                case SpecifyColor.yellowCrown:
                    r = "Huang";
                    break;

                case SpecifyColor.purpleGem:
                    r = "Zi";
                    break;

                case SpecifyColor.redBook:
                    r = "Hong";
                    break;

                case SpecifyColor.greenLeaf:
                    r = "Lv";
            }
        } else if (Number(l) == ObstacleAllType.ColorBox) {
            a = "M_A_MuHe";
            i = "idle_" + o;
            switch (e.SpecifyColor) {
                case SpecifyColor.any:
                    r = "YiBan";
                    break;

                case SpecifyColor.blueShield:
                    r = "Lan";
                    break;

                case SpecifyColor.yellowCrown:
                    r = "Huang";
                    break;

                case SpecifyColor.purpleGem:
                    r = "Zi";
                    break;

                case SpecifyColor.redBook:
                    r = "Hong";
                    break;

                case SpecifyColor.greenLeaf:
                    r = "Lv";
            }
        } else if (Number(l) == ObstacleAllType.Grass) {
            a = "G_A_LvCaoPi";
            i = 1 == o ? "idle_2" : "idle_1";
        } else if (Number(l) == ObstacleAllType.Egg) {
            a = "J_A_JiDan";
            i = "idle_1";
        } else if (Number(l) == ObstacleAllType.Vase) {
            a = "H_A_HuaPing";
            i = 1 == o ? "idle_2" : "idle_1";
        } else {
            if (Number(l) == ObstacleAllType.Honey) return null;
            if (Number(l) == ObstacleAllType.Oyster) {
                a = "MuLi";
                i = 1 == o ? "explode_2" : 2 == o ? "explode_1" : "idle_1";
            } else if (Number(l) == ObstacleAllType.Rock) {
                a = "Y_A_YanShi-BaoShi";
                i = 2 == o ? "idle_1" : 1 == o ? "idle_2" : "idle_3";
            } else if (Number(l) == ObstacleAllType.Flowerpot) {
                a = "H_A_HuanPen";
                i = 1 == o ? "idle_2" : "idle_1";
            } else if (Number(l) == ObstacleAllType.Stone) {
                a = "S_A_ShiXiang";
                i = "idle_" + o;
            } else if (Number(l) == ObstacleAllType.PorcelainPig) {
                a = "X_A_XiaoZhu";
                i = "idle_1";
            } else {
                if (Number(l) == ObstacleAllType.MailBox) return null;
                if (Number(l) == ObstacleAllType.Bird) return null;
                if (Number(l) == ObstacleAllType.GoldCoin) {
                    a = "QZ_HongBao";
                    i = "idle_2";
                } else if (Number(l) == ObstacleAllType.PurpleFlower) {
                    a = "G_A_ZiCaoPi";
                    i = 1 == o ? "idle_2" : "idle_1";
                } else {
                    if (Number(l) == ObstacleAllType.MagicHat) return null;
                    if (Number(l) == ObstacleAllType.GrassLand) {
                        a = "G_A_GuanMuCong";
                        i = "idle_1";
                        5 == e.Hp ? i = "idle_1" : 4 == e.Hp ? i = "explode_1" : 3 == e.Hp ? i = "explode_2" : 2 == e.Hp ? i = "explode_3" : 1 == e.Hp && (i = "explode_4");
                    } else if (Number(l) == ObstacleAllType.ColorBottle){} else if (Number(l) == ObstacleAllType.SafeBox) {
                        a = "BaoXianXiang";
                        i = "idle_" + o;
                    } else Number(l) == ObstacleAllType.cupboard || Number(l) == ObstacleAllType.Icicle || (Number(l),
                        ObstacleAllType.curtain);
                }
            }
        }
        if (a && i) {
            cc.resources.load("spine/obstacleEffect/" + a, sp.SkeletonData, function (e, a) {
                if (e) n.error("未找到障碍物特效动画预制体", e); else {
                    t.getComponent(sp.Skeleton).skeletonData = a;
                    t.getComponent(sp.Skeleton).setAnimation(0, i, false);
                    r && t.getComponent(sp.Skeleton).setSkin(r);
                }
            });
            return true;
        }
    };
    public playMagicAni(e, t, a) {
        void 0 === a && (a = false);
        var o = "", i = "", r = false, n = false;
        if (a) {
            o = "Spit";
            r = false;
            i = "Close";
            n = false;
        } else if (1 == t) {
            d.playMagicStateAudio(2);
            o = "idle_3";
            r = true;
        } else if (2 == t) {
            d.playMagicStateAudio(1);
            o = "idle_2";
            r = false;
        } else if (t <= 0) {
            o = "jump_1";
            r = false;
            i = "idle_1";
            n = false;
        }
        if (e.getComponent(sp.Skeleton).skeletonData) {
            e.getComponent(sp.Skeleton).clearTracks();
            e.getComponent(sp.Skeleton).setAnimation(0, o, r);
            i && e.getComponent(sp.Skeleton).addAnimation(0, i, n);
        } else cc.resources.load("spine/obstacleEffect/MoFaMao", sp.SkeletonData, function (t, a) {
            e.getComponent(sp.Skeleton).skeletonData = a;
            e.getComponent(sp.Skeleton).setAnimation(0, o, r);
            i && e.getComponent(sp.Skeleton).addAnimation(0, i, n);
        });
    };
    public playMailBoxAni(e, t, a?) {
        void 0 === a && (a = false);
        cc.resources.load("spine/all/Y_A_YouXiang", sp.SkeletonData, function (a, o) {
            a && n.error("未找到障碍物特效动画预制体", a);
            e.getComponent(sp.Skeleton).skeletonData = o;
            e.getComponent(sp.Skeleton).clearTracks();
            if (t.enable) {
                e.getComponent(sp.Skeleton).setAnimation(0, "explode_1", false);
                e.getComponent(sp.Skeleton).addAnimation(0, "idle_1", false);
            } else {
                e.getComponent(sp.Skeleton).setAnimation(0, "explode_2", false);
                e.getComponent(sp.Skeleton).addAnimation(0, "idle_2", false);
            }
        });
    };
    public birdAniCompleteListener(e) {
        var t = this;
        if (e) {
            var a = e.getComponent(sp.Skeleton);
            a.setCompleteListener(function () {
                e && ("fall_1" == a.animation ? a.setAnimation(0, "fall_2", true) : "blink" == a.animation || "idle" == a.animation || "lookOn_R" == a.animation || "lookOn_L" == a.animation ? t.playBirdIdleAni(e) : "fall_3" == a.animation && t.playBirdIdleAni(e));
            });
        }
    };
    public loadBirdIdleAni(e) {
        var t = this;
        cc.resources.load("spine/obstacleEffect/XiaoNiao", sp.SkeletonData, function (a, o) {
            if (a) n.error("未找到障碍物特效动画预制体", a); else if (cc.isValid(e)) {
                e.getComponent(sp.Skeleton).skeletonData = o;
                var i = e.getComponent(sp.Skeleton), r = "";
                switch (s.getRandomNumber(1, 5)) {
                    case 1:
                        r = "blink";
                        break;

                    case 2:
                        r = "idle";
                        break;

                    case 3:
                        r = "lookOn_R";
                        break;

                    case 4:
                        r = "lookOn_L";
                }
                i.setAnimation(0, "" + r, false);
                t.birdAniCompleteListener(e);
            }
        });
    };
    public playBirdIdleAni(e, t?) {
        void 0 === t && (t = false);
        var a = e.getComponent(sp.Skeleton);
        if (a.skeletonData) {
            var o = e.getComponent(sp.Skeleton);
            i = "";
            switch (s.getRandomNumber(1, 5)) {
                case 1:
                    i = "blink";
                    break;

                case 2:
                    i = "idle";
                    break;

                case 3:
                    i = "lookOn_R";
                    break;

                case 4:
                    i = "lookOn_L";
            }
            o.setAnimation(0, "" + i, false);
        } else {
            a.skeletonData = this.birdFlyEffectSpData;
            var i = "";
            switch (s.getRandomNumber(1, 5)) {
                case 1:
                    i = "blink";
                    break;

                case 2:
                    i = "idle";
                    break;

                case 3:
                    i = "lookOn_R";
                    break;

                case 4:
                    i = "lookOn_L";
            }
            a.setAnimation(0, "" + i, false);
            this.birdAniCompleteListener(e);
        }
    };
    public playBirdDownAni(e, t) {
        var a = e.getComponent(sp.Skeleton);
        t ? a.setAnimation(0, "fall_3", false) : a.setAnimation(0, "fall_1", false);
    };
    public playSafeBoxAni(e, t) {
        var a = e.Hp;
        a <= 0 || cc.resources.load("spine/all/BaoXianXiang", sp.SkeletonData, function (e, o) {
            e && n.error("未找到障碍物特效动画预制体", e);
            t.getComponent(sp.Skeleton).skeletonData = o;
            t.getComponent(sp.Skeleton).setAnimation(0, "idle_" + a, false);
        });
    };
    public playGrassLand(e, t) {
        var a = e.Hp;
        a <= 0 || cc.resources.load("spine/all/BaoXianXiang", sp.SkeletonData, function (e, o) {
            e && n.error("未找到障碍物特效动画预制体", e);
            t.getComponent(sp.Skeleton).skeletonData = o;
            t.getComponent(sp.Skeleton).setAnimation(0, "idle_" + a, false);
        });
    };
    public playDrillDestoryAni(e, t, a, o, i) {
        a.setPosition(this.getV3Pos(e.row, e.col));
        a.x -= MatchGameConfig.ITEM_WIDTH / 2;
        a.y += MatchGameConfig.ITEM_HEIGHT / 2;
        a.parent = this.effectParent;
        var r = a.getComponent(g);
        r.initDrill(t, 0, o);
        var n = r.drillSpineNode.getComponent(sp.Skeleton), l = cc.v3(a.x, a.y), s = 0;
        switch (t) {
            case 0:
                l.y += 1600;
                s = 2;
                break;

            case 1:
                l.x += 800;
                s = 1;
                break;

            case 2:
                l.y -= 1600;
                s = 2;
                break;

            case 3:
                l.x -= 800;
                s = 1;
        }
        n.setAnimation(0, "idle_3", false);
        n.addAnimation(0, "idle_4", false);
        n.setCompleteListener(function () {
            "idle_3" == n.animation && cc.tween(a).to(s, {
                position: l
            }).call(function () {
                a.removeFromParent();
                i && i();
            }).start();
        });
    };
    public playDrillFlyAni(e, t, a, o) {
        var i = this.createObstacleEffectItem(e, this.matchFlySpData);
        i.setCompleteListener(function () { });
        i.setAnimation(0, "idle_1", false);
        i.setSkin(y.setMatchAniSkin(a));
        var r = cc.v2(i.node.x - t.x > 0 ? t.x + 50 : t.x - 50, t.y - 300);
        cc.tween(i.node).bezierTo(.6, cc.v2(i.node.position), r, cc.v2(t)).call(function () {
            i.setCompleteListener(null);
            i.skeletonData = null;
            l.putNode(u.MatchAniPool.obstacleAniPrefab, i.node);
            o && o();
        }).start();
    };
    public getV3Pos(e, t) {
        return cc.v3(e * MatchGameConfig.ITEM_WIDTH , -t * MatchGameConfig.ITEM_HEIGHT);
    };
    public getV3Pos1(e, t) {
        return cc.v3(e * MatchGameConfig.ITEM_WIDTH + MatchGameConfig.ITEM_WIDTH / 2, -t * MatchGameConfig.ITEM_HEIGHT - MatchGameConfig.ITEM_HEIGHT / 2);
    };
}

export default ObstacleAniCtrl.getInstance();